package kinectKata.service;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import kinectData.models.ProjectSettings;
import kinectData.models.Receiver;

/**
 * 
 * @author Lauren Norrie (norrielm)
 */
public class DeviceSender {

	private static Receiver<String> logger;

	public DeviceSender(Receiver<String> logger) {
		this.logger = logger;
	}
	
	public static void sendToDevice(String ip, int port, String message) {
		try {
			DatagramSocket socket = new DatagramSocket();
			byte[] buf = message.getBytes();
			System.out.println(String.format("Sending message '%s' to %s:%d", message, ip, port));
			DatagramPacket packet = new DatagramPacket(buf, buf.length, InetAddress.getByName(ip),
				port);
			socket.send(packet);
		} catch (Exception e) {
			System.out.println(String.format("Failed to send to device  '%s' to %s:%d", e.getMessage(), ip, port));
			e.printStackTrace();
		}
	}
}
